#import "DDQianBao.h"
@interface DDQianBao()
@property (nonatomic, strong) DDImageView *IMG;
@property (nonatomic, strong) CCLabel *label;
@end
@implementation DDQianBao
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.IMG.hidden = NO;
        self.bounds = CGRectMake(0, 0, self.label.bounds.size.width + self.label.bounds.size.height + 5, self.label.bounds.size.height);
    }
    return self;
}
- (CCLabel *)label
{
    if (!_label)
    {
        _label = [[CCLabel alloc] init];
        _label.font = FONT(UIFontWeightRegular, 15);
        _label.textColor = helpermanger().getPara().color;
        _label.text = @"优先钱包扣款";
        _label.backgroundColor = [UIColor clearColor];
        [self addSubview:_label];
        _label.c_right.equal(self);
        _label.c_centerY.equal(self);
    }
    return _label;
}
- (DDImageView *)IMG
{
    if (!_IMG)
    {
        _IMG = [[DDImageView alloc] init];
        _IMG.imageName = @"selected";
        _IMG.layer.cornerRadius = self.label.bounds.size.height / 2.0;
        _IMG.layer.masksToBounds = YES;
        _IMG.backgroundColor = helpermanger().getPara().color;
        [self addSubview:_IMG];
        _IMG.c_right.equal(self.label.c_left).with.coffset(-5);
        _IMG.c_centerY.equal(self);
        _IMG.c_size.equal(CGSizeMake(self.label.bounds.size.height, self.label.bounds.size.height));
    }
    return _IMG;
}
DDQianBaoManager qianBaoManager()
{
    DDQianBaoManager manager =
    {
        _getPara,
        _setPara
    };
    return manager;
};
static DDQianBaoPara _para;
static DDQianBaoPara _getPara()
{
    return _para;
}
static void _setPara(DDQianBao *view, DDQianBaoPara para)
{
    _para = para;
    view.label.text =  [NSString stringWithFormat:@"优先钱包扣款(余额:%@元)",_para.title];
    view.bounds = CGRectMake(0, 0, view.label.bounds.size.width + view.label.bounds.size.height + 5, view.label.bounds.size.height);
    view.label.c_size.equal(view.label.bounds.size);
    view.c_size.equal(view.bounds.size);
}

- (void)setSelected:(BOOL)selected
{
    [super setSelected:selected];
    self.label.textColor = (self.selected)?helpermanger().getPara().color:TEXT_GRAY_COLOR;
    self.IMG.backgroundColor = (self.selected)?helpermanger().getPara().color:[UIColor clearColor];
    self.IMG.imageName = (self.selected)?@"selected":@"unselect";
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    self.label.alpha = 0.5;
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [super touchesEnded:touches withEvent:event];
    self.label.alpha = 1.0;
}
@end
